package com.example.api.controller;

import com.example.api.annotation.LoginInterceptor;
import com.example.dao.domain.dto.LoginDto;
import com.example.api.service.RedisService;
import com.example.api.service.UserService;
import com.example.util.result.RestResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
public class UserController {
    @Resource
    private UserService userService;

    @Resource
    private RedisService redisService;

    @RequestMapping("/")
    public String index() throws Exception {
        redisService.set("1", "1", 60);
        return "hello";
    }

    @RequestMapping("/1")
    public String index1() throws Exception {
        return "hello1";
    }

    @RequestMapping("/fun")
    public String fun(@RequestParam int id) throws Exception {
        if (id == 2) {
            int temp = 1 / 0;
        }

        return id + "";
    }

    @LoginInterceptor
    @RequestMapping("/login")
    @ApiOperation(value = "用户登录接口", httpMethod = "POST")
    public RestResult login(@RequestBody @Validated LoginDto loginDto) throws Exception {
        return userService.queryUserByNameAndPwd(loginDto);
    }
}
